package com.fourth_groups.shopping121store.ui.person.view;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import com.fourth_groups.shopping121store.R;
import com.fourth_groups.shopping121store.bean.Person_horizontal;

import java.io.Serializable;

public class GradmeActivity extends AppCompatActivity {

    private WebView webview;
    private ProgressBar progress;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gradme);
        webview = (WebView) findViewById(R.id.persent_webView);
        progress = (ProgressBar) findViewById(R.id.prent_progress);
        Intent intent = getIntent();
        final String url = intent.getStringExtra("url");
            webview.loadUrl(url);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.setWebChromeClient(new Mywebprogress());
        webview.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                webview.loadUrl(url);
                return true;
            }
        });

    }
   class Mywebprogress extends WebChromeClient{
       @Override
       public void onProgressChanged(WebView view, int newProgress) {
            if (newProgress==100){
                progress.setVisibility(View.GONE);
            }else {
                if (progress.getVisibility()==View.GONE){
                    progress.setVisibility(View.VISIBLE);
                    progress.setProgress(newProgress);
                }
                super.onProgressChanged(view, newProgress);
            }

       }
   }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
            webview.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
